package com.example.list;

import androidx.appcompat.app.AppCompatActivity;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import java.util.Locale;

public class InternationalActivity extends AppCompatActivity {
    private TextView tv_space;
    private String language; //当前设置的语言
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_international);
        tv_space = (TextView) findViewById(R.id.tv_line_letterSpace);
    }

    public void simple(View view) {
        language = Locale.SIMPLIFIED_CHINESE.toString();
        update();
        tv_space.setText(getResources().getString(R.string.china));
    }

    public void complex(View view) {
        //繁体中文
        language = Locale.TRADITIONAL_CHINESE.toString();
        update();
        tv_space.setText(getResources().getString(R.string.china));
    }
    void update(){
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        if (language.equals("zh_TW")) {
            conf.locale = Locale.TAIWAN;
        } else {
            conf.locale = Locale.CHINESE;
        }
        res.updateConfiguration(conf, dm);
    }
}